package _17define;

public class Demo2 {
    public static void main(String[] args) {
        String str = "Hello, World!";

        System.out.println("字符串长度: " + str.length());

        char chAtIndex = str.charAt(7);
        System.out.println("指定位置的字符: " + chAtIndex);


        String substring = str.substring(0, 5);
        System.out.println("截取子字符串: " + substring);


        int index = str.indexOf("World");
        System.out.println("查找子字符串的位置: " + index);


        boolean contains = str.contains("lo");
        System.out.println("是否包含子字符串: " + contains);


        String replaced = str.replace("Hello", "Goodbye");
        System.out.println("替换子字符串: " + replaced);


        String trimed = str.trim();
        System.out.println("去除前后空格: " + trimed);

        String upperCase = str.toUpperCase();
        System.out.println("转换为大写: " + upperCase);
        String lowerCase = str.toLowerCase();
        System.out.println("转换为小写: " + lowerCase);

        // 获取字符数组
        char[] charArray = str.toCharArray();
        for (char c : charArray) {
            System.out.print(c + " ");
        }
        System.out.println(); // 输出: H e l l o , W o r l d !

        // 获取字节数组
        byte[] bytes = str.getBytes();
        for (byte b : bytes) {
            System.out.print(b + " ");
        }
        System.out.println(); // 输出: 48 50 59 65 65 69 70 71 72 73 74 65 79 82


        // 比较两个字符串
        String anotherStr = "Hello, World!";
        boolean equals = str.equals(anotherStr);
        System.out.println("比较两个字符串: " + equals); // 输出: 比较两个字符串: true

        // 获取特定位置的字符
        char charAt = str.charAt(0);
        System.out.println("获取特定位置的字符: " + charAt); // 输出: 获取特定位置的字符: H

        // 获取所有字符
        char[] allChars = str.toCharArray();
        for (char c : allChars) {
            System.out.print(c + " ");
        }
        System.out.println(); // 输出: H e l l o , W o r l d !

        // 获取所有字符的字节表示
        byte[] allBytes = str.getBytes();
        for (byte b : allBytes) {
            System.out.print(b + " ");
        }
        System.out.println(); // 输出: 48 50 59 65 65 69 70 71 72 73 74 65 79 82

        // 获取所有字符的Unicode值
        int[] unicodeValues = new int[allChars.length];
        for (int i = 0; i < allChars.length; i++) {
            unicodeValues[i] = (int) allChars[i];
            System.out.print(unicodeValues[i] + " ");
        }
        System.out.println(); // 输出: 72 101 108 108 111 32 87 111 114 108 100 32 83 116 111 114

        // 获取所有字符的Unicode范围
        int minUnicode = unicodeValues[0];
        int maxUnicode = unicodeValues[allChars.length - 1];
        System.out.println("最小Unicode值: " + minUnicode);
        System.out.println("最大Unicode值: " + maxUnicode); // 输出: 最小Unicode值: 72 最大Unicode值: 116

    }
}